/* 
 * File:   SelfDrawable.cpp
 * Author: RedEyedKiller
 * 
 * Created on 22 Σεπτέμβριος 2010, 7:17 μμ
 */

#include "SelfDrawable.h"
#include "Camera.h"
#include "sdl/GraphicsCore.h"

SelfDrawable::SelfDrawable()
{
}

SelfDrawable::SelfDrawable(const SelfDrawable& orig):Drawable(orig)
{
}

SelfDrawable::~SelfDrawable()
{
}

bool SelfDrawable::IsVisible(const Camera& camera) const
{
    if (alwaysVisible) return true;
    if (!m_visible) return false;
    int posX = position.GetX();
    int posY = position.GetY();
    return (camera.GetRect()->GetLeft() <= posX + m_display->GetRawData()->GetWidth() * GetScale().GetX() && 
            camera.GetRect()->GetTotalWidth() <= posX) &&
            (camera.GetRect()->GetTop() <= posY + m_display->GetRawData()->GetHeight()  * GetScale().GetY()&& 
            camera.GetRect()->GetTotalHeight() <= posY);
}

int SelfDrawable::GetX() const
{
    return position.GetX();
}

void SelfDrawable::SetX(int newX)
{
    position.SetX(newX);
}

int SelfDrawable::GetWidth() const
{
    return Drawable::GetWidth();
}

int SelfDrawable::GetHeight() const
{
    return Drawable::GetHeight();
}

int SelfDrawable::GetY() const
{
    return position.GetY();
}

void SelfDrawable::SetY(int newY)
{
    position.SetY(newY);
}

Math::Vector2F SelfDrawable::GetPosition() const
{
    return position;
}

void SelfDrawable::SetPosition(const Math::Vector2F& position)
{
    this->position = position;
}

void SelfDrawable::Draw(sdl::GraphicsCore *gCore, Camera *camera)
{
    if (m_display != NULL)
    {
        gCore->Render(*m_display->GetRawData(),m_clip,m_color,
                      Math::Vector2F(GetX() - camera->GetRect()->GetLeft(), GetY() - camera->GetRect()->GetTop()),
                      m_scale,m_angle,m_flip);
    }
}

void SelfDrawable::SetAlwaysVisible(bool alwaysVisible)
{
    this->alwaysVisible = alwaysVisible;
}

bool SelfDrawable::IsAlwaysVisible() const
{
    return alwaysVisible;
}
